var _tools = require("../../../utils/tools.js"), _tools2 = _interopRequireDefault(_tools);

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var that, app = getApp();

function e(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var i = e(require("./modules/base-canvas-palette.js")), n = e(require("../../../utils/wx-promisify/wx-promisify.js")), d = e(require("./modules/handle-create-img.js")), h = ((0, 
n.default)(wx.getSetting), 0), p = 0;

Page({
    data: {
        loading: !1,
        shareshow: !1,
        id: 0,
        imageStyle: "",
        img_height: 0,
        sIndex: 0,
        poster_images: [],
        creat_img: !1
    },
    onReady: function() {
        wx.setNavigationBarColor({
            frontColor: "#000000",
            backgroundColor: "#000000"
        });
        var t = {
            action: "poster",
            contr: "help",
            token: wx.getStorageSync("token"),
            id: this.data.id
        };
        _tools2.default.request(t, function(t) {
            that.setData(t.info), that.generatePoster();
        }), this.data.img_height = getApp().globalData.systemInfo.screenHeight - 180;
    },
    onLoad: function(t) {
        (that = this).data.id = t.id;
    },
    onShow: function() {},
    chooseTheme: function(t) {
        this.setData({
            sIndex: t.currentTarget.dataset.index
        }), this.generatePoster();
    },
    generatePoster: function() {
        var t = this.data.bargain_poster_bg, e = 1100;
        this.setData({
            z_h: e,
            creat_img: !0
        });
        var a = [ {
            type: "image",
            url: t,
            css: {
                top: "0rpx",
                left: "0rpx",
                width: "680rpx",
                height: e + "rpx",
                mode: "scaleToFill"
            }
        }, {
            type: "image",
            url: this.data.member.headimgurl,
            css: {
                top: "50rpx",
                left: "297rpx",
                width: "96rpx",
                height: "96rpx",
                borderRadius: "100px",
                borderWidth: "1px",
                borderColor: "#ffffff"
            }
        }, {
            type: "text",
            text: this.data.member.nickname,
            css: Object.assign({
                top: "165rpx",
                left: "339rpx",
                align: "center",
                maxLines: 1,
                width: "300rpx",
                color: "#ffffff",
                fontSize: "22rpx",
                fontWeight: "bold"
            })
        }, {
            type: "text",
            text: this.data.poster_txt,
            css: Object.assign({
                top: "210rpx",
                left: "335rpx",
                align: "center",
                maxLines: 2,
                width: "410rpx",
                color: "#ffffff",
                fontSize: "32rpx",
                fontWeight: "bold"
            })
        }, {
            type: "image",
            url: this.data.goods.cover_image,
            css: {
                top: "320rpx",
                left: "95rpx",
                width: "480rpx",
                height: "480rpx"
            }
        }, {
            type: "image",
            url: this.data.code,
            css: {
                top: "830rpx",
                left: "70rpx",
                width: "180rpx",
                height: "180rpx",
                borderRadius: "179px",
                borderWidth: "1px",
                borderColor: "#ffffff"
            }
        }, {
            type: "text",
            text: "长按识别小程序码",
            css: Object.assign({
                top: "920rpx",
                left: "390rpx",
                align: "center",
                maxLines: 2,
                width: "410rpx",
                color: "#ffffff",
                fontSize: "28rpx"
            })
        } ];
        this.data.poster = {
            content: a,
            z_h: e
        }, console.log(a), wx.showLoading({
            title: "正在生成海报",
            mask: !0
        }), d.default.doCreateImg(this);
        try {
            getApp().sensors.track("XMClick", {
                ck_module: "保存海报",
                page: "抽奖海报"
            });
        } catch (t) {}
    },
    imgErr: function(t) {
        console.log(t), d.default.createImgFail(t);
    },
    onImgOK: function(t) {
        wx.hideLoading();
        var e = "height:" + this.data.img_height + "px";
        this.setData({
            poster_img: t.detail.path,
            imageStyle: e,
            creat_img: !1
        });
    },
    savePoster: function() {
        wx.saveImageToPhotosAlbum({
            filePath: this.data.poster_img,
            success: function(t) {
                wx.showToast({
                    title: "保存成功"
                });
            }
        });
    },
    previewImage: function() {
        wx.previewImage({
            current: that.data.poster_img,
            urls: [ that.data.poster_img ]
        });
    }
});